﻿using System;
using Model;

namespace ViewLayer
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        User user;
        Project project;

        protected void Page_Load(object sender, EventArgs e)
        {
            user = (User)Session["User"];
            project = (Project)Session["Project"];
            if (user == null)
            {
                Response.Redirect("../../Account/Login.aspx");
            }
            else
            {
                lblUserName.Text = user.Nome;
                if (project != null)
                {
                    lblProjectName.Text = project.Nome;
                    lblProjectName.Visible = true;

                    lblDate.Text = project.DataInicio.ToString("dd/MM/yyyy") + " - " + project.DataFim.ToString("dd/MM/yyyy");
                    lblDate.Visible = true;

                     
                }
            }
            if (user != null && project != null)
            {
                this.NavigationMenu.FindItem("Info").Enabled = true;
            }
        }

        protected void lkbLogOut_Click(object sender, EventArgs e)
        {
            Session["User"] = null;
            if (Request.UrlReferrer.ToString().Contains("Default") || Request.UrlReferrer.ToString().Contains("About"))
            {
                Response.Redirect("../Account/Login.aspx");
            }
            else
            {
                Response.Redirect("../../Account/Login.aspx");
            }
        }
    }
}